package com.ticket.sass.admin.mapper;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ticket.sass.common.entity.tenant.TakeTicketOrderEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author ywb
 * @since 2024-05-07
 */
public interface TakeTicketOrderMapper extends BaseMapper<TakeTicketOrderEntity> {
    @Select("SELECT ticket_order.*,u.cellphone FROM take_ticket_orders ticket_order LEFT JOIN users u ON ticket_order.user_id = u.id ${ew.customSqlSegment}")
    IPage<TakeTicketOrderEntity> listQuery(Page<TakeTicketOrderEntity> page, @Param(Constants.WRAPPER) QueryWrapper<TakeTicketOrderEntity> queryWrapper);
    
    @Select("""
        SELECT  
            COUNT(ticket_order.id) AS total_orders,
            SUM(ticket_order.ticket_num) AS total_tickets
        FROM  
            take_ticket_orders ticket_order  
        LEFT JOIN  
            users u  
        ON  
            ticket_order.user_id = u.id
       ${ew.customSqlSegment}
        """)
    TakeTicketOrderEntity count(@Param(Constants.WRAPPER) QueryWrapper<TakeTicketOrderEntity> queryWrapper);
}
